#include "yocto/utest/run.hpp"

#include "core/full-dyn.hpp"
#include "core/lj.hpp"
#include "core/fcc.hpp"

#include "yocto/wtime.hpp"
#include "yocto/ios/ocstream.hpp"

using namespace FastMD;

YOCTO_UNIT_TEST_IMPL(full_dyn)
{
	std::cerr << "Testing Dynamics" << std::endl;
	LJ           lj(1,1);
	wtime        chrono;
	const size_t niter = 10;
	const char  *tmx_name = "tmx-full-nve.dat";
	bool isothermal = false;
	for( int i=1; i < argc; ++i )
	{
		const string opt = argv[i];
		if( opt == "isothermal" )
		{
			isothermal = true;
			tmx_name   = "tmx-full-nvt.dat";
		}
	}
	
	{
		ios::ocstream fp(tmx_name,false);
	}
	
	for( size_t m=1; m <= 11; ++m )
	{
		const U3D    cr(m,m,m);
		const size_t np = 4 * cr.items();
		const Real   L  = __pow( np, __ONE/__THREE );
		Frame F(3,np);
		std::cerr << "m=" << m << ", np=" << np << ", L=" << L << std::endl;
		F.set_box( V3D(L,L,L) );
		FullDynamics dyn;
		FCC::Build( F[0], cr, F.box, F.ibox, 0 );
		double tmx = 0;
		for( size_t i=0; i < niter; ++i )
		{
			chrono.start();
			dyn.eval( F, lj, isothermal );
			tmx += chrono.query();
		}
		tmx /= niter;
		std::cerr << "\tV/pt= " << F.V/np << ", time= " << tmx*1000.0 << " ms" << std::endl;
		ios::ocstream fp(tmx_name,true);
		fp("%u %.5e\n", unsigned(m), tmx );
	}
	
}
YOCTO_UNIT_TEST_DONE()
